﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class admin_Modify : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
          if (Session["admin"] == null)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "parent.location.href='Login.aspx'", true);

            }
         else if (!Page.IsPostBack)
           {
               ///根据传递的pid获取产品信息
               DbAccess db = new DbAccess();
               string pid = Request.QueryString.Get("pid");
               if (pid == null)
                   Response.Redirect("Login.aspx");
               else
               {
                   ///绑定商品类型
                 string sql = "select * from Category";
                DataSet dsCat = db.GetDataSet(sql);
                Category.DataSource = dsCat.Tables[0].DefaultView;
                Category.DataTextField = "Category";
                Category.DataValueField = "id";
                Category.DataBind();
                 string sqlPro = "select * from product where ProId='" + pid + "'";
                 DataSet dsPro = db.GetDataSet(sqlPro);
                 if (dsPro.Tables[0].Rows.Count > 0)
                 {
                     ProName.Text = dsPro.Tables[0].Rows[0][1].ToString();
                     FreeTextBox1.Text = dsPro.Tables[0].Rows[0][2].ToString();
                     Hot.SelectedValue = dsPro.Tables[0].Rows[0][3].ToString();
                     Tejia.SelectedValue = dsPro.Tables[0].Rows[0][4].ToString();
                     Jipin.SelectedValue = dsPro.Tables[0].Rows[0][5].ToString();
                     Upfile1.setPath(dsPro.Tables[0].Rows[0][6].ToString());
                     MemberPrice.Text = dsPro.Tables[0].Rows[0][7].ToString();
                     MarketPrice.Text = dsPro.Tables[0].Rows[0][8].ToString();
                     Category.SelectedValue = dsPro.Tables[0].Rows[0][9].ToString();
                     tblNum.Text = dsPro.Tables[0].Rows[0][11].ToString();
                 
                 }

               }
              

           }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        try
        {
            string ProId=Request.QueryString.Get("pid").ToString();
            string pName = ProName.Text;
            string pCat = Category.SelectedValue;
            string pMar = MarketPrice.Text;
            string pMem = MemberPrice.Text;
            string isHot = Hot.SelectedValue;
            string isSale = Tejia.SelectedValue;
            string isFal = Jipin.SelectedValue;
            string pic = Upfile1.getpath();
            string content = FreeTextBox1.Text;
            string proNum=tblNum.Text;
            if(proNum==null)
                proNum="0";
            string sql = "update product set ProName='" + pName + "',Content='" + content + "',isHot=" + isHot + ",isSale=" + isSale + ",isFaience=" + isFal + ",ProPic='" + pic + "',MemberPrice=" + pMem + ",MarketPrice=" + pMar + ",Category=" + pCat + ",ProNum="+proNum+" where ProId="+ProId+"";

            DbAccess db = new DbAccess();
            if (db.ExecuteSql(sql))
            {
                
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('修改成功')", true);
                Response.Redirect("Manager.aspx");

            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('修改失败')", true);

            
            }

        }
        catch
        { 
        
        }
    }
   
}
